package leetcode;

import leetcode.map.Lc743_2;

import java.util.Arrays;

public class Lc31 {



    public void nextPermutation(int[] nums) {

        for (int i = nums.length - 1; i > 0 ; i--) {
            if (nums[i] > nums[i-1]) {
                int j = i-1;
                for (int k = nums.length - 1; k >= i ; k--) {
                    if (nums[k] > nums[j]) {
                        int tmp = nums[k];
                        nums[k] = nums[j];
                        nums[j] = tmp;
                        Arrays.sort(nums, j + 1, nums.length);
                        return;
                    }
                }
            }
        }
        Arrays.sort(nums);
    }

    public static void main(String[] args) {
        Lc31 lc31 = new Lc31();
        int[] x = {3,2,1};
        lc31.nextPermutation(x);
        for (int i = 0; i < x.length; i++) {
            System.out.println(x[i]);
        }

    }

}
